import request from '@/utils/request';
import { PageResponse } from '@/interface/pages';

/**
 * 获取分页列表
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getRepairList = <T = any[]>(
  dbname: string,
  params: API.repair.PageListDto
) => {
  return request<PageResponse<T>>({
    url: `/admin/repair/${dbname}`,
    method: 'get',
    params
  });
};

/**
 * 详情
 *
 * @param id
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getRepairDetail = <T = any>(dbname: string, id: number) => {
  return request<T>({
    url: `/admin/repair/${dbname}/${id}`,
    method: 'get'
  });
};

/**
 * 编辑
 *
 * @param id
 * @param data
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateRepair = (
  dbname: string,
  id: number,
  data: API.repair.EntityDto
) => {
  return request({
    url: `/admin/repair/${dbname}/${id}`,
    method: 'put',
    data
  });
};

/**
 * 执行模块
 *
 * @param id
 * @param data
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const actionRepairModule = (name: string, data: any) => {
  return request({
    url: `/admin/repair/module/${name}`,
    method: 'post',
    data
  });
};
